package com.jd.tuning.jvm.async;

import lombok.SneakyThrows;

import java.util.Date;

/**
 * 本地调用异步化
 */
public class AsyncDemoThread {

    private  void subBiz1() throws InterruptedException {
        Thread.sleep(1000L);
        System.out.println(new Date()+"subBiz1");
    }

    private  void subBiz2() throws InterruptedException {
        Thread.sleep(1000L);
        System.out.println(new Date()+"subBiz2");
    }

    private  void saveOpLog() throws InterruptedException {
        //手动创建线程的方式，在实际项目中不可取
        new Thread(new SaveOpLogThread()).start();
    }

    private  void biz() throws InterruptedException{
        this.subBiz1();
        saveOpLog();
        this.subBiz2();
    }

    public static void main(String[] args) throws InterruptedException {
        new AsyncDemoThread().biz();
    }
}

class SaveOpLogThread implements  Runnable{
    @SneakyThrows
    @Override
    public void run() {
        Thread.sleep(1000L);
        System.out.println(new Date()+"插入操作日志");
    }
}
